package fr.greta.centre.action;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import fr.greta.centre.dao.CandidatureDAOImpl;
import fr.greta.centre.dao.CursusDAOImpl;
import fr.greta.centre.metier.Candidature;


public class AfficherEtatCandidatureCandidat extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AfficherEtatCandidatureCandidat() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 * @author baptiste
	 * Recupere l'id candidat,
	 * récupere les objets Candidatures et les passe en attribut de requete,
	 * Appelle la JSP AfficherEtatCandidatureandidat
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		int idCandidat = 1; //(int) request.getAttribute("idCandidat");
		CandidatureDAOImpl dao = new CandidatureDAOImpl();
		CursusDAOImpl daoCur = new CursusDAOImpl();
		ArrayList<Candidature> lesCandidatures = dao.findByIdPersonne(idCandidat);
		ArrayList<String> lesLibelles = new ArrayList<String>();
		
		for (Candidature c : lesCandidatures){
			String unLibelle = daoCur.findByKey(c.getPromotion().getIdCursus()).getLibelle();
			lesLibelles.add(unLibelle);
		}
		request.setAttribute("lesCandidatures", lesCandidatures);
		request.setAttribute("lesLibelles", lesLibelles);
		request.getRequestDispatcher("afficherEtatCandidaturesCandidat.jsp").forward(request, response);
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}		


}
